use(["public/javascripts/service/track_searchService.js","public/common/classNames.js", "public/javascripts/widget/slider/slider.js"], function(track_searchService,classNames, SliderComponent) {
    var cn = classNames;
    var PageComponent = React.createClass({
        componentWillMount : function() {
            for(var i in track_searchService) this[i] = track_searchService[i].bind(this);
        },
        getInitialState: function () {
            return {list : {}, search : ''};
        },
        render:function() {
            var data = this.state, self = this, list = this.state.list, loading = this.state.loading,
                        search = data.search.split(","),
                       dirty = this.state.dirty;

            var renderTrack = function(track){
                return track.map(function(item){
                    if(typeof item === 'boolean') return;
                    var datetime = item.messageTime.split(' ');
                        return (<li>
                            <span className="date">{datetime[0]}</span>
                            <div className="msg">
                                <span className="time">{datetime[1]}</span>
                                <p>{item.trackMessage}</p>
                            </div>
                        </li>);
                    });
            };

            var getNoResult = function(num){
                search = search.filter(function(i){
                    if(i != num) return i;
                });
            };

            var renderTracks = function(tracks){
                var track = [];
                for(var i in tracks){
                    if(i === 'open') continue;
                    (function(i){
                    track.push(
                        <li>
                        <h6>
                            <span>子单号：{i}</span>
                            <i className={cn({open:tracks[i][0] === true})} onClick={self.openChild.bind(self,tracks[i])}></i>
                        </h6>
                        <ul className={cn('child-body',{'open': (typeof tracks[i][0] === 'boolean' && tracks[i][0])})}>
                        {renderTrack(tracks[i])}
                        </ul>
                        </li>
                        );
                    })(i);
                }
                return track;
            };

            var renderList = function(){
                 var lists  = [];
                 for(var i in list){
                     getNoResult(i);
                     (function(i){
                     lists.push(<div className="item">
                                <h6 className="item-header">
                                    运单号: {i}
                                    <i className={cn({open:list[i].open})} onClick={self.openTrack.bind(self,list[i])}></i>
                                </h6>
                                <ul className={cn('item-body',{'open':list[i].open})}>{renderTracks(list[i])}</ul></div>);
                    })(i)
                 }
                 return lists;
            }();
            return ~init;
        }
    });

    if(typeof ReactDOM != "undefined") {
        ReactDOM.render(<PageComponent data={storage}/>, document.getElementById('container'));
    }
    module.exports = PageComponent;
});